// 接口方法, 只负责调用一个接口, 返回一个Promise对象
import request from '@/utils/request'
import store from '@/store'
// import store from '@/store'
// 获取所有频道数据
export const allChannelListAPI = () => {
  return request({
    url: '/v1_0/channels'
  })
}

// 登录接口配置
export const loginAPI = ({ mobile, code }) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}
// 定义刷新token的接口方法 为了token续签
export const refreshTokenAPI = () => request({
  url: '/v1_0/authorizations',
  method: 'PUT',
  headers: {
    Authorization: `Bearer ${store.state.refresh_token}`
  }
})

// 循环铺设home组件导航栏的请求，获取用户已选
export const channelAPI = () => {
  return request({
    url: '/v1_0/user/channels'
    // headers: {
    //   Authorization: 'Bearer ' + store.state.token
    // }
  })
}
// 更新用户已选
export const updateChannelApi = ({ channels }) => {
  return request({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels
    }
    // headers: {
    //   Authorization: 'Bearer ' + store.state.token
    // }
  })
}
// 文章-获取列表
export const articlesListAPI = ({ channel_id, pre_timestamp }) => { // 形参的解构赋值
  return request({
    url: '/v1_0/articles',
    params: {
      channel_id: channel_id,
      timestamp: pre_timestamp || new Date().getTime() + ''
    }
  })
}

// 文章的不感兴趣接口
export const articleDislikeApi = ({ artId }) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    // headers: {
    //   Authorization: 'Bearer ' + store.state.token
    // },
    data: {
      target: artId
    }
  })
}
// 举报接口
export const articleReportsApi = ({ artId, type }) => {
  return request({
    url: '/v1_0/article/reports',
    method: 'POST',
    // headers: {
    //   Authorization: 'Bearer ' + store.state.token
    // },
    data: {
      target: artId,
      type: type + '',
      remark: type === 0 ? '问题描述' : null
    }
  })
}
// 搜索联想菜单接口
export const suggestSearchAPI = ({ params }) => {
  return request({
    url: '/v1_0/suggestion',
    method: 'GET',
    params: {
      q: params
    }
  })
}
// 搜索框搜索出来点击联想菜单或点回车或点历史记录后跳转的页面数据接口---搜索结果列表
export const searchResultAPI = ({ kw, page = 1 }) => {
  return request({
    url: '/v1_0/search',
    method: 'GET',
    params: {
      q: kw,
      page: page
    }
  })
}
// 文章列表，就是能看到关注的那个页面的请求数据
export const articleDetailApi = ({ aid }) => {
  return request({
    url: `/v1_0/articles/${aid}`
  })
}
// 文章-关注作者
export const guanzhuzuozheApi = ({ aid }) => {
  return request({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target: aid
    }
  })
}
// 文章-取关作者
export const quguanzuozheApi = ({ aid }) => {
  return request({
    url: `/v1_0/user/followings/${aid}`,
    method: 'DELETE'

  })
}
// 文章-喜欢
export const likeApi = ({ aid }) => {
  return request({
    url: '/v1_0/article/likings',
    method: 'POST',
    data: {
      target: aid
    }
  })
}

// 文章-不喜欢
export const dislikeApi = ({ aid }) => {
  return request({
    url: `/v1_0/article/likings/${aid}`,
    method: 'DELETE'

  })
}
// 评论-获取列表
export const commentListApi = ({ artId, offset, limit }) => {
  return request({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: artId,
      offset: offset,
      limit: limit

    }
  })
}
// 评论点赞
export const dianzan = ({ comId }) => {
  return request({
    url: '/v1_0/comment/likings',
    method: 'POST',
    data: {
      target: comId
    }
  })
}
// 评论取消点赞
export const quxiaodianzan = ({ comId }) => {
  return request({
    url: `/v1_0/comment/likings/${comId}`,
    method: 'DELETE'
  })
}
// 发布评论

export const sendCommitApi = ({ artId, content }) => {
  return request({
    url: '/v1_0/comments',
    method: 'POST',
    data: {
      target: artId,
      content: content

    }
  })
}

// 获取用户基本信息(我的页面)
export const getUserApi = () => {
  return request({
    url: '/v1_0/user'
  })
}
// 获取用户基本信息生日之类的(编辑页面)
export const getUserProfileApi = () => {
  return request({
    url: '/v1_0/user/profile'
  })
}
// 更新用户头像
export const userPhotoApi = (formObj) => {
  return request({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data: formObj
  })
}
// 更新用户资料
export const updateUserProfileApi = ({ userName, birthday }) => {
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data: {
      name: userName,
      birthday: birthday
    }
  })
}
